/*     */ package com.newcrm.webapi.sub;
/*     */ 
/*     */ import com.newcrm.bean.CompanyInfo;
/*     */ import com.newcrm.bean.User;
/*     */ import com.newcrm.db.QisoukeManager;
/*     */ import com.newcrm.exception.NotFoundException;
/*     */ import com.newcrm.util.JsoupManager;
/*     */ import com.newcrm.util.Util;
/*     */ import com.newcrm.webapi.AbstractAction;
/*     */ import com.newcrm.webapi.AbstractHttpServlet;
/*     */ import java.io.IOException;
/*     */ import java.io.PrintWriter;
/*     */ import java.net.URLEncoder;
/*     */ import javax.servlet.ServletException;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.apache.log4j.Logger;
/*     */ import org.jsoup.nodes.Document;
/*     */ 
/*     */ public class QisoukeSearchCompany extends AbstractAction
/*     */ {
/*  32 */   private static Logger logger = Logger.getLogger(QisoukeSearchCompany.class
/*  33 */     .getName());
/*     */ 
/*     */   public QisoukeSearchCompany(AbstractHttpServlet servlet)
/*     */   {
/*  36 */     super(servlet);
/*     */   }
/*     */ 
/*     */   public void parse(HttpServletRequest request, HttpServletResponse response)
/*     */     throws IOException, ServletException, NotFoundException
/*     */   {
/*  43 */     User user = super.getLoginUser(request);
/*  44 */     CompanyInfo company = super.getCompany(request);
/*     */ 
/*  47 */     String key = Util.getURLParameter(request.getParameter("k"));
/*  48 */     if (key == null) {
/*  49 */       key = "";
/*     */     }
/*     */ 
/*  53 */     String province = Util.getURLParameter(request.getParameter("p"));
/*  54 */     if (province == null) {
/*  55 */       province = "";
/*     */     }
/*     */ 
/*  59 */     String city = Util.getURLParameter(request.getParameter("c"));
/*  60 */     if (city == null) {
/*  61 */       city = "";
/*     */     }
/*     */ 
/*  65 */     String s = Util.getURLParameter(request.getParameter("s"));
/*  66 */     if (s == null) {
/*  67 */       s = "";
/*     */     }
/*     */ 
/*  71 */     String mobile = Util.getURLParameter(request.getParameter("m"));
/*  72 */     if (mobile == null) {
/*  73 */       mobile = "";
/*     */     }
/*     */ 
/*  77 */     String fax = Util.getURLParameter(request.getParameter("f"));
/*  78 */     if (fax == null) {
/*  79 */       fax = "";
/*     */     }
/*     */ 
/*  83 */     String email = Util.getURLParameter(request.getParameter("e"));
/*  84 */     if (email == null) {
/*  85 */       email = "";
/*     */     }
/*     */ 
/*  88 */     String name = Util.getURLParameter(request.getParameter("n"));
/*  89 */     if (name == null) {
/*  90 */       name = "";
/*     */     }
/*     */ 
/*  94 */     String domain = Util.getURLParameter(request.getParameter("d"));
/*  95 */     if (domain == null) {
/*  96 */       domain = "";
/*     */     }
/*     */ 
/* 100 */     String fee = Util.getURLParameter(request.getParameter("fee"));
/* 101 */     if (fee == null) {
/* 102 */       fee = "";
/*     */     }
/*     */ 
/* 106 */     String day = Util.getURLParameter(request.getParameter("day"));
/* 107 */     if (day == null) {
/* 108 */       day = "";
/*     */     }
/*     */ 
/* 112 */     String baidu = Util.getURLParameter(request.getParameter("b"));
/* 113 */     if (baidu == null) {
/* 114 */       baidu = "";
/*     */     }
/*     */ 
/* 118 */     int page = Util.getURLIntParameter(request.getParameter("page"));
/* 119 */     if (page <= 0) {
/* 120 */       page = 1;
/*     */     }
/*     */ 
/* 123 */     StringBuffer searchUrl = new StringBuffer();
/* 124 */     searchUrl.append("http://so.qikebao.com/qisouke?k=")
/* 125 */       .append(URLEncoder.encode(key, "UTF-8")).append("&p=")
/* 126 */       .append(URLEncoder.encode(province, "UTF-8")).append("&c=")
/* 127 */       .append(URLEncoder.encode(city, "UTF-8")).append("&s=")
/* 128 */       .append(URLEncoder.encode(s, "UTF-8")).append("&m=")
/* 129 */       .append(URLEncoder.encode(mobile, "UTF-8")).append("&f=")
/* 130 */       .append(URLEncoder.encode(fax, "UTF-8")).append("&e=")
/* 131 */       .append(URLEncoder.encode(email, "UTF-8")).append("&n=")
/* 132 */       .append(URLEncoder.encode(name, "UTF-8")).append("&d=")
/* 133 */       .append(URLEncoder.encode(domain, "UTF-8")).append("&fee=")
/* 134 */       .append(URLEncoder.encode(fee, "UTF-8")).append("&b=")
/* 135 */       .append(URLEncoder.encode(baidu, "UTF-8")).append("&day=")
/* 136 */       .append(URLEncoder.encode(day, "UTF-8")).append("&page=")
/* 137 */       .append(page);
/*     */ 
/* 139 */     response.setContentType("text/html;charset=utf-8");
/* 140 */     PrintWriter out = response.getWriter();
/*     */     try
/*     */     {
/* 143 */       Document doc = JsoupManager.getSearchResult(user, company, 
/* 144 */         searchUrl.toString());
/* 145 */       out.println(doc.text());
/*     */ 
/* 148 */       QisoukeManager manager = new QisoukeManager();
/* 149 */       manager.add(key, page, user.companyId, user.userId);
/*     */     }
/*     */     catch (Exception e) {
/*     */       try {
/* 153 */         Thread.sleep(1000L);
/*     */       }
/*     */       catch (InterruptedException localInterruptedException) {
/*     */       }
/*     */       try {
/* 158 */         Document doc = JsoupManager.getSearchResult(user, company, 
/* 159 */           searchUrl.toString());
/* 160 */         out.println(doc.text());
/*     */ 
/* 163 */         QisoukeManager manager = new QisoukeManager();
/* 164 */         manager.add(key, page, user.companyId, user.userId);
/*     */       } catch (Exception e1) {
/* 166 */         logger.warn("search failed", e1);
/* 167 */         super.showErrorMessage(response, "搜索超时，请稍后再试");
/* 168 */         return;
/*     */       }
/*     */     }
/* 171 */     out.flush();
/* 172 */     out.close();
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.webapi.sub.QisoukeSearchCompany
 * JD-Core Version:    0.6.1
 */